<%@ page contentType="text/html; charset=UTF-8" import="com.pub.database.*,java.util.*"%>
<jsp:useBean id="DataViewForm" scope="request" class="com.pub.database.DataViewForm" />
<jsp:useBean id="stbSQL" scope="request" class="java.lang.StringBuffer" />
<jsp:useBean id="strDataViewHtml" scope="request" class="java.lang.String" />
<%
	 ArrayList<Hashtable<String,Object>> laltColRelation = new ArrayList<Hashtable<String,Object>>();
	 Hashtable<String,Object> lhtColRelationDetail = new Hashtable<String,Object>();
	 
     DataView dataView = null;
     try{
       if(request.getParameter("db_alias")!=null && !request.getParameter("db_alias").trim().equals("")){
         dataView =  new DataView(request.getParameter("db_alias"),false,"big5","big5");

         stbSQL.append(" sesion.sql_hash_value = sqlarea.hash_value ");
         stbSQL.append("and sesion.sql_address    = sqlarea.address ");
         stbSQL.append("and sesion.username is not null ");
         stbSQL.append("and ((sysdate-sesion.LOGON_TIME)*24)>");
         stbSQL.append((request.getParameter("time_out")==null ? "0" : request.getParameter("time_out")));

         lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "sesion.sid");
         lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'Session 編號'");
         lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "0");
         lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,
         "width='5%' align='center'");

         laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
         lhtColRelationDetail.clear();

         lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "sesion.machine");
         lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'Machine'");
         lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "0");
         lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,
         "width='5%' align='center'");

         laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
         lhtColRelationDetail.clear();

         lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "sesion.LOGON_TIME");
         lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "'登入時間'");
         lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "0");
         lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,
         "width='15%' align='center'");

         laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
         lhtColRelationDetail.clear();

         lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "logon_min");
         lhtColRelationDetail.put(dataView.STR_FIELD_SUB_SQL, "trim(to_char(((sysdate-sesion.LOGON_TIME)*24),'999.99'))");
         lhtColRelationDetail.put(dataView.STR_FIELD_TITLE,"'已登入小時數'");
         lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "0");
         lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,"WIDTH='12%' align='center'");

         laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
         lhtColRelationDetail.clear();

         lhtColRelationDetail.put(dataView.STR_FIELD_NAME, "sql_text");
         lhtColRelationDetail.put(dataView.STR_FIELD_TITLE, "SQL");
         lhtColRelationDetail.put(dataView.STR_FIELD_KIND, "TEXTAREA");
         lhtColRelationDetail.put(dataView.STR_FIELD_HTML, "<textarea cols='90' rows='5'>");
         lhtColRelationDetail.put(dataView.STR_FIELD_VALUE, "SQL_TEXT");
         lhtColRelationDetail.put(dataView.STR_FIELD_PROPERTY,
         " align='center'");

         laltColRelation.add(new Hashtable<String,Object>(lhtColRelationDetail));
         lhtColRelationDetail.clear();

         //設定上一頁與下一頁按鈕的form action(通常為母頁即本頁)
         DataViewForm.setPageActionURI(request.getRequestURI());

         //設定要query的table list(以逗號隔開)
         DataViewForm.setTablesList(" v$sqlarea sqlarea, v$session sesion ");

         //依欄位查詢值組合sql where
         DataViewForm.setSQLCondition(stbSQL.toString());

         //設定排序的欄位
         DataViewForm.setOrderByFields("sesion.MACHINE,sesion.LOGON_TIME");

         //排序的方法(正序或倒序)
         DataViewForm.setOrderBySeq("asc");

         //group by 的欄位(以逗號隔開)
         DataViewForm.setGroupBy(null);

         //Having 的欄位(有設定group by時此欄位才有作用)
         DataViewForm.setHaving(null);

         //將欄位相關設定值設入DataViewForm
         DataViewForm.setColRelationUseArrayList(laltColRelation);

         //設定DataView Header的<tr> html屬性
         DataViewForm.setTableHeaderHtml(
         "class='td_head_grid' align='center'  width='100%'");
         DataViewForm.setTableDataTrHtml("id='tr%sn%' name='tr%sn%' onmouseover=\"this.className='td_content_over'\" onmouseout=\"this.className='td_content'\"");
         DataViewForm.setPageRowCount(0);//全部秀出
         DataViewForm.setJumpPageButtonShow(false); //是否要秀出上下頁按鈕
         DataViewForm.setPageBtnOnTop(true); //將button and rows info 秀在頂端
         DataViewForm.setPageBtnOnButtom(false); //將button and rows info 秀在底端
         DataViewForm.setFilterShow(false); //是否要秀出過濾選擇欄位
         DataViewForm.setJumpPageShow(false); //是否要秀出跳頁下拉式選單
         DataViewForm.setRowsInfoShow(true); //是否要秀出筆數資訊
         DataViewForm.setRowPageShow(false); //是否要秀出每頁筆數控制欄
         DataViewForm.setExcelShow(false); //是否要秀出轉Excel button
         DataViewForm.setOrderEnable(false); //是否要提供排序點選功能
         DataViewForm.setShowHeaderWhenNoData(true); //當ResultSet無資料是否要秀Header
         DataViewForm.setAddNewShow(false); //是否秀出新增鈕
         DataViewForm.setBatchUpdateButtonShow(false); //是否秀出批次更新鈕(需在jsp自行增加evt_dataview_btnBatchUpdate_onclick() js function)

         strDataViewHtml=dataView.getOutputDataView(DataViewForm);
       }
    }
    catch(Exception e){
      e.printStackTrace();
    }
    finally{
      laltColRelation.clear();
      DataViewForm=null;
      dataView=null;
    }
%>
<html>
<head>
<title>
GetDBSessionLastSQL
</title>
<LINK HREF="/PUBPAGE/general/workflow.css" REL="STYLESHEET" TYPE="TEXT/CSS">
</head>
<body bgcolor="#ffffff">
<form action="<%=request.getRequestURI()%>" method="POST">
選取要看的DB：
            <select name="db_alias">
              <option value="NPIDB_ANDY" <%=request.getParameter("db_alias")!=null && request.getParameter("db_alias").equals("NPIDB_ANDY") ? "selected" : ""%>>NPIDB</option>
              <option value="PIDORA02_ANDY" <%=request.getParameter("db_alias")!=null && request.getParameter("db_alias").equals("PIDORA02_ANDY") ? "selected" : ""%>>PIDORA02</option>
              <option value="KMDB_ANDY" <%=request.getParameter("db_alias")!=null && request.getParameter("db_alias").equals("KMDB_ANDY") ? "selected" : ""%>>KMDB</option>
              <option value="BUGDB_ANDY" <%=request.getParameter("db_alias")!=null && request.getParameter("db_alias").equals("BUGDB_ANDY") ? "selected" : ""%>>BUGDB</option>
              <option value="WORKFLOW_P_ANDY" <%=request.getParameter("db_alias")!=null && request.getParameter("db_alias").equals("WORKFLOW_P_ANDY") ? "selected" : ""%>>WORKFLOW</option>
              <option value="RMADB_ANDY" <%=request.getParameter("db_alias")!=null && request.getParameter("db_alias").equals("RMADB_ANDY") ? "selected" : ""%>>RMADB</option>
            </select><br />
已登入時間(小時)：<input type="text" name="time_out" size="10" value="<%=(request.getParameter("time_out")==null ? "0" : request.getParameter("time_out"))%>"/>
<input type="submit" value="view" />
</form>
<%=strDataViewHtml %>
</body>
</html>
